﻿#include "parserlog.h"

using namespace std;

static QList<QMap<QString, QString> > switchTimesList;
static QSet<QString> yearTimes;

QMap<QString, QString> ParserLog::month {
    {"Jan", "1"},
    {"Feb", "2"},
    {"Mar", "3"},
    {"Apr", "4"},
    {"May", "5"},
    {"Jun", "6"},
    {"Jul", "7"},
    {"Aug", "8"},
    {"Sep", "9"},
    {"Oct", "10"},
    {"Nov", "11"},
    {"Dec", "12"},
};

ParserLog::ParserLog()
{
}

void ParserLog::formatString(QString &str)
{
    str.replace(QRegExp("[\\s]+"), " ");
}

void ParserLog::reverseQList(QList<QMap<QString, QString> > &str)
{
    QList<QMap<QString, QString> > temp;
    for (QList<QMap<QString, QString> >::reverse_iterator it=str.rbegin(); it!=str.rend(); it++) {
        temp.append(*it);
    }

    str.clear();
    for (QList<QMap<QString, QString> >::iterator it=temp.begin(); it!=temp.end(); it++) {
        str.append(*it);
    }
}

void ParserLog::parserSwitch(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QStringList lineContent;
    QMap<QString, QString> map;
    QMap<QString, QString> timesMap;
    QString weekMatch = "(Mon|Tue|Wed|Thu|Fri|Sat|Sun)";
    int weekPosition = 0;

    getcontent.getWtmpContent(allContent);

    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        //去除多余空格，并拆分
        formatString(*it);
        lineContent = it->split(" ");

        if (it->contains("shutdown")) {
            lineContent[0] = "关机";
        }
        else if (it->contains("reboot")) {
            lineContent[0] = "开机";
        }
        else {
            lineContent[0] += "用户登录";
        }

        //获取week的位置
        weekPosition = lineContent.indexOf(QRegExp(weekMatch));
        const QString date = lineContent[weekPosition+4] + "-" + month[lineContent[weekPosition+1]] + "-" + lineContent[weekPosition+2];

        map.insert("日期", date);
        map.insert("时间", lineContent[weekPosition+3]);
        map.insert("动作", lineContent[0]);

        logList.append(map);

        /************用于开关机次数统计 begin*************/
        //插入年，自动去重
        yearTimes.insert(lineContent[weekPosition+4]);

        timesMap.insert("year", lineContent[weekPosition+4]);
        timesMap.insert("month", month[lineContent[weekPosition+1]]);

        if (it->contains("tty")) {
            timesMap.insert("login", "1");
            timesMap.insert("boot", "0");
            timesMap.insert("shutdown", "0");
        }
        else if (it->contains("reboot")) {
            timesMap.insert("login", "0");
            timesMap.insert("boot", "1");
            timesMap.insert("shutdown", "1");
        }
        else if (it->contains("shutdown")) {
            timesMap.insert("login", "0");
            timesMap.insert("boot", "0");
            timesMap.insert("shutdown", "1");
        }
        else {
            continue;
        }
        switchTimesList << timesMap;
        /************用于开关机次数统计 end*************/
    }
//    qDebug() << switchTimesList;
}

void ParserLog::parserSysInfo(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QStringList lineContent;
    QString regExpString = "";
    QRegExp rx;
    QString host = "";
    QString description = "";
    QString leftString = "";
    QString rightString = "";
    QString action = "";
    QString date = "";
    QString time = "";
    QString monthMatch = "^(Jan|Fre|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
    QMap<QString, QString> map;

    getcontent.getSyslogContent(allContent);

    //正则匹配表达式
    regExpString = monthMatch + "[ ]*\\d+[ ]*\\d+:\\d+:\\d+[ ]*[^ ][ ]*[^:]+:";
    rx.setPattern(regExpString);
    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        //如果不匹配就跳过
        if (-1 == rx.indexIn(*it)) {
            continue;
        }
        lineContent = it->split(" "); //将字符串以空格为分隔符分隔
        if (lineContent[1] != "") {
            host = lineContent[HOSTINDEX];//下标为3的是主机名
        }
        else {
            host = lineContent[HOSTINDEX+1];//下标为4的是主机名
        }
        map.insert("主机名", host);
        lineContent = it->split(host);//以主机名分隔
        leftString = lineContent[0];//日期和时间
        rightString = lineContent[1];
        action = rightString.mid(0, rightString.indexOf(": "));
        map.insert("动作", action);
        description = rightString.mid(rightString.indexOf(": ")+1);
        map.insert("描述", description.simplified());

        formatString(leftString); //去除多余的空格
        lineContent = leftString.split(" ");
        date = month[lineContent[0]] + "-" + lineContent[1];
        map.insert("日期", date);
        time = lineContent[2];
        map.insert("时间", time);
        logList << map;
    }
//    qDebug() << logList;
}

void ParserLog::parserSysBoot(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QStringList lineContent;
    QString action = "";
    QString description = "";
    QMap<QString, QString> map;
    QRegExp rx;
    QString regExpString = "\\[*\\]";
    int index = 0;

    getcontent.getBootlogContent(allContent);

    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        formatString(*it);
        rx.setPattern(regExpString);
        if ((index = rx.indexIn(*it)) == -1) {
            QRegExp rxp;
            rxp.setPattern("^WARNING|ERROR|rootfs");
            if ((*it).indexOf(rxp) != -1) {
                action = rxp.cap(0);
                description = (*it).mid((*it).indexOf(":")+1);
            }
            else {
                action = "";
                description = *it;
            }
            description.replace(QRegExp("^ "), "");
        }
        else {
            action = (*it).mid(0, index+1);
            description = (*it).mid(index+1);
            description.replace(QRegExp("^ "), "");
        }

        map.insert("动作", action);
        map.insert("描述", description);
        logList << map;
    }
//    qDebug() << logList;
}

void ParserLog::parserPackage(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QStringList lineContent;
    QString status = "";
    QString package = "";
    QMap<QString, QString> map;

    getcontent.getDpkglogContent(allContent);

    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        package = "";
        lineContent = it->split(" ");
        //过滤status
        status = lineContent[2];
        if (status == "status" || status == "configure" ||
            status == "startup" || status == "trigproc") {
            continue;
        }
        map.insert("日期", lineContent[0]);
        map.insert("时间", lineContent[1]);
        map.insert("状态", lineContent[2]);
        for (int i=3; i<lineContent.size() ;i++ ) {
            package += " " + lineContent[i];
        }
        package.replace(QRegExp("^ "), "");
        package.replace(QRegExp(" <none>"), "");
        map.insert("软件包", package);
        logList << map;
    }
    //    qDebug() << logList;
}

void ParserLog::parserKernel(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QStringList lineContent;
    QString regExpString = "";
    QRegExp rx;
    QString host = "";
    QString description = "";
    QString temp = "";
    QString date = "";
    QString time = "";
    QString monthMatch = "^(Jan|Fre|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
    QMap<QString, QString> map;

    getcontent.getKernelContent(allContent);

    //正则匹配表达式
    regExpString = monthMatch + "[ ]*\\d+[ ]*\\d+:\\d+:\\d+[ ]*[^ ][ ]*[^:]+:";
    rx.setPattern(regExpString);

    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        //如果不匹配就跳过
        if (-1 == rx.indexIn(*it)) {
            continue;
        }
        lineContent = it->split(" ");
        if (lineContent[1] != "") {
            host = lineContent[HOSTINDEX];//下标为3的是主机名
        }
        else {
            host = lineContent[HOSTINDEX+1];//下标为4的是主机名
        }
        map.insert("主机名", host);
        lineContent = it->split(host);
        temp = lineContent[0];
        description = lineContent[1];
        map.insert("描述", description.simplified());
        formatString(temp); //去除多余的空格
        lineContent = temp.split(" ");
        date = month[lineContent[0]] + "-" + lineContent[1];
        map.insert("日期", date);
        time = lineContent[2];
        map.insert("时间", time);
        logList << map;
    }
//    qDebug() << logList;
}

void ParserLog::parserSoftwareUpdate(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QStringList lineContent;
    QString description = "";
    QMap<QString, QString> map;

    getcontent.getSoftwareUpdateContent(allContent);

    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        description = "";
        lineContent = it->split(" ");

        map.insert("日期", lineContent[1]);
        //清除时间中最后一个:
        lineContent[2].replace(QRegExp(":$"), "");
        map.insert("时间", lineContent[2]);
        for (int i=3; i<lineContent.size() ;i++ ) {
            description += " " + lineContent[i];
        }
        description.replace(QRegExp("^ "), "");
        map.insert("描述", description);
        logList << map;
    }
//    qDebug() << logList;
}

void ParserLog::parserPrint(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QStringList lineContent;
    QStringList date;
    QStringList time;
    QString description = "";
    QString tempString = "";
    QString dateString = "";
    QString timeString = "";
    QString hourString = "";
    QMap<QString, QString> map;

    getcontent.getPrintContent(allContent);

    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        //取出[11/Aug/2022:00:09:09 +0800]
        tempString = it->mid(it->indexOf("[") + 1, (it->indexOf("]") - it->indexOf("[") - 1));
        dateString = tempString.section(':', 0, 0);//取出11/Aug/2022
        timeString = tempString.section(":", 1, 3);//取出00:09:09 +0800
        date = dateString.split("/");//以/分割11/Aug/2022
        dateString = date[2] + "-" + month[date[1]] + "-" + date[0];
        map.insert("日期", dateString);
        time = timeString.split(" ");//以" "分割00:09:09 +0800
        map.insert("时间", time[0]);
        lineContent = it->split("\"");
        map.insert("动作", lineContent[1]);
        map.insert("描述", lineContent[2].simplified());
        lineContent = it->split(" ");
        map.insert("主机名", lineContent[0]);
        map.insert("用户", lineContent[2]);

        logList << map;
    }
//    qDebug() << logList;
}

void ParserLog::parserBurn(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QMap<QString, QString> map;

    getcontent.getBurnContent(allContent);

    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        map.insert("描述", *it);
        logList << map;
    }
//    qDebug() << logList;
}

void ParserLog::parserAudit(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QMap<QString, QString> map;

    getcontent.getAuditContent(allContent);

    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        map.insert("描述", *it);
        logList << map;
    }
}

void ParserLog::parserSession(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QMap<QString, QString> map;

    getcontent.getSessionContent(allContent);

    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        map.insert("描述", *it);
        logList << map;
    }
//    qDebug() << logList;
}

void ParserLog::parserXorg(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QString loadingTime = "";
    QString description = "";
    QMap<QString, QString> map;

    getcontent.getXorgContent(allContent);

    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        if (it->indexOf("[") != -1) {
            QStringList temp = it->split("]");
            loadingTime = temp[0] + "]";
            description = temp[1];
            if (description.length() == 1) {
                continue;
            }
            description.replace(QRegExp("^ "), "");
            description.replace(QRegExp("^\t"), "");
            map.insert("加载时间", loadingTime);
            map.insert("描述", description);
        }
        else {
            map.insert("加载时间", "");
            it->replace(QRegExp("^\t"), "");
            map.insert("描述", *it);
        }
        logList << map;
    }
    //    qDebug() << logList;
}

void ParserLog::parserApplication(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QStringList lineContent;
    QString regExpString = "";
    QRegExp rxMonth;
    QString description = "";
    QString leftString = "";
    QString rightString = "";
    QString action = "";
    QString source = "(nemo|cdos-appstore|file-compress)";
    QString date = "";
    QString time = "";
    QString monthMatch = "^(Jan|Fre|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
    QMap<QString, QString> map;

    getcontent.getApplicationContent(allContent);

    //正则匹配表达式
    regExpString = monthMatch + "[ ]*\\d+[ ]*\\d+:\\d+:\\d+[ ]*[^ ][ ]*" + source + "*[^:]+:";
    rxMonth.setPattern(regExpString);
    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        //如果不匹配就跳过
        if (-1 == rxMonth.indexIn(*it)) {
            continue;
        }
        formatString(*it); //去除多余的空格
        lineContent = it->split(" "); //将字符串以空格为分隔符分隔
        lineContent = it->split(lineContent[3]);//下标为3的是主机名,以主机名分隔
        leftString = lineContent[0];//日期和时间
        rightString = lineContent[1];
        action = rightString.mid(0, rightString.indexOf(": "));

        if (action.contains("cdos-appstore")) {
            map.insert("来源", "软件中心");
        }
        else if(action.contains("file-compress")) {
            map.insert("来源", "方德压缩");
        }
        else if(action.contains("nemo")) {
            map.insert("来源", "文件管理器");
        }
        else {
            continue;
        }

        description = rightString.mid(rightString.indexOf(": ")+1);
        map.insert("信息", description.simplified());

        formatString(leftString); //去除多余的空格
        lineContent = leftString.split(" ");
        date = month[lineContent[0]] + "-" + lineContent[1];
        map.insert("日期", date);
        time = lineContent[2];
        map.insert("时间", time);
        logList << map;
    }
//    qDebug() << logList;
}

void ParserLog::parserSwitchTimes(QList<QMap<QString, QString> > &logList)
{
    QMap<QString, QString> map;
    int temp = 0;

    for (QSet<QString>::ConstIterator it=yearTimes.begin(); it!=yearTimes.end(); it++) {
        map.insert("年份", *it);
        //定义一个二维数组，用于记录12个月，每个月中登录/开机/关机次数
        int monthTimes[12][3] = {{0}};

        for (int i=0; i<switchTimesList.size(); i++) {
            if (switchTimesList.at(i).value("year") == *it) {
                temp = switchTimesList.at(i).value("month").toUInt();
                if (switchTimesList.at(i).value("login") == "1") {
                    monthTimes[temp-1][0] = monthTimes[temp-1][0] + 1;
                }
                else if (switchTimesList.at(i).value("boot") == "1") {
                    monthTimes[temp-1][1] = monthTimes[temp-1][1] + 1;
                }
                else {
                    monthTimes[temp-1][2] = monthTimes[temp-1][2] + 1;
                }
            }
        }

#if 0
        //打印调试
        for (int i=0; i<12; i++) {
            for (int j=0; j<3; j++) {
                cout << monthTimes[i][j] << " ";
            }
            cout << endl;
        }
#endif

        for (int i=0; i<12; i++) {
            temp = monthTimes[i][0] + monthTimes[i][1] + monthTimes[i][2];
            if (temp) {
                map.insert("月份", QString::number(i+1));
                map.insert("登录次数", QString::number(monthTimes[i][0]));
                map.insert("开机次数", QString::number(monthTimes[i][1]));
                map.insert("关机次数", QString::number(monthTimes[i][2]));
                logList << map;
            }
        }
    }
    reverseQList(logList);
//    qDebug() << logList;
}

void ParserLog::parserDebug(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QStringList lineContent;
    QString regExpString = "";
    QRegExp rx;
    QString host = "";
    QString description = "";
    QString leftString = "";
    QString rightString = "";
    QString action = "";
    QString date = "";
    QString time = "";
    QString monthMatch = "^(Jan|Fre|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
    QMap<QString, QString> map;

    getcontent.getDebugContent(allContent);

    //正则匹配表达式
    regExpString = monthMatch + "[ ]*\\d+[ ]*\\d+:\\d+:\\d+[ ]*[^ ][ ]*[^:]+:";
    rx.setPattern(regExpString);
    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        //如果不匹配就跳过
        if (-1 == rx.indexIn(*it)) {
            continue;
        }
        lineContent = it->split(" "); //将字符串以空格为分隔符分隔
        if (lineContent[1] != "") {
            host = lineContent[HOSTINDEX];//下标为3的是主机名
        }
        else {
            host = lineContent[HOSTINDEX+1];//下标为4的是主机名
        }
        map.insert("主机名", host);
        lineContent = it->split(host);//以主机名分隔
        leftString = lineContent[0];//日期和时间
        rightString = lineContent[1];
        action = rightString.mid(0, rightString.indexOf(": "));
        map.insert("动作", action);
        description = rightString.mid(rightString.indexOf(": ")+1);
        map.insert("描述", description.simplified());
        formatString(leftString); //去除多余的空格
        lineContent = leftString.split(" ");
        date = month[lineContent[0]] + "-" + lineContent[1];
        map.insert("日期", date);
        time = lineContent[2];
        map.insert("时间", time);
        logList << map;
    }
//    qDebug() << logList;
}

void ParserLog::parserInfo(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QStringList lineContent;
    QString regExpString = "";
    QRegExp rx;
    QString host = "";
    QString description = "";
    QString leftString = "";
    QString rightString = "";
    QString action = "";
    QString date = "";
    QString time = "";
    QString monthMatch = "^(Jan|Fre|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
    QMap<QString, QString> map;

    getcontent.getInfoContent(allContent);

    //正则匹配表达式
    regExpString = monthMatch + "[ ]*\\d+[ ]*\\d+:\\d+:\\d+[ ]*[^ ][ ]*[^:]+:";
    rx.setPattern(regExpString);
    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        //如果不匹配就跳过
        if (-1 == rx.indexIn(*it)) {
            continue;
        }
        lineContent = it->split(" "); //将字符串以空格为分隔符分隔
        if (lineContent[1] != "") {
            host = lineContent[HOSTINDEX];//下标为3的是主机名
        }
        else {
            host = lineContent[HOSTINDEX+1];//下标为4的是主机名
        }
        map.insert("主机名", host);
        lineContent = it->split(host);//以主机名分隔
        leftString = lineContent[0];//日期和时间
        rightString = lineContent[1];
        action = rightString.mid(0, rightString.indexOf(": "));
        map.insert("动作", action);
        description = rightString.mid(rightString.indexOf(": ")+1);
        map.insert("描述", description.simplified());
        formatString(leftString); //去除多余的空格
        lineContent = leftString.split(" ");
        date = month[lineContent[0]] + "-" + lineContent[1];
        map.insert("日期", date);
        time = lineContent[2];
        map.insert("时间", time);
        logList << map;
    }
    //    qDebug() << logList;
}

void ParserLog::parserNotice(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QStringList lineContent;
    QString regExpString = "";
    QRegExp rx;
    QString host = "";
    QString description = "";
    QString leftString = "";
    QString rightString = "";
    QString action = "";
    QString date = "";
    QString time = "";
    QString monthMatch = "^(Jan|Fre|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
    QMap<QString, QString> map;

    getcontent.getNoticeContent(allContent);

    //正则匹配表达式
    regExpString = monthMatch + "[ ]*\\d+[ ]*\\d+:\\d+:\\d+[ ]*[^ ][ ]*[^:]+:";
    rx.setPattern(regExpString);
    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        //如果不匹配就跳过
        if (-1 == rx.indexIn(*it)) {
            continue;
        }
        lineContent = it->split(" "); //将字符串以空格为分隔符分隔
        if (lineContent[1] != "") {
            host = lineContent[HOSTINDEX];//下标为3的是主机名
        }
        else {
            host = lineContent[HOSTINDEX+1];//下标为4的是主机名
        }
        map.insert("主机名", host);
        lineContent = it->split(host);//以主机名分隔
        leftString = lineContent[0];//日期和时间
        rightString = lineContent[1];
        action = rightString.mid(0, rightString.indexOf(": "));
        map.insert("动作", action);
        description = rightString.mid(rightString.indexOf(": ")+1);
        map.insert("描述", description.simplified());
        formatString(leftString); //去除多余的空格
        lineContent = leftString.split(" ");
        date = month[lineContent[0]] + "-" + lineContent[1];
        map.insert("日期", date);
        time = lineContent[2];
        map.insert("时间", time);
        logList << map;
    }
    //    qDebug() << logList;
}

void ParserLog::parserWarning(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QStringList lineContent;
    QString regExpString = "";
    QRegExp rx;
    QString host = "";
    QString description = "";
    QString leftString = "";
    QString rightString = "";
    QString action = "";
    QString date = "";
    QString time = "";
    QString monthMatch = "^(Jan|Fre|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
    QMap<QString, QString> map;

    getcontent.getWarningContent(allContent);

    //正则匹配表达式
    regExpString = monthMatch + "[ ]*\\d+[ ]*\\d+:\\d+:\\d+[ ]*[^ ][ ]*[^:]+:";
    rx.setPattern(regExpString);
    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        //如果不匹配就跳过
        if (-1 == rx.indexIn(*it)) {
            continue;
        }
        lineContent = it->split(" "); //将字符串以空格为分隔符分隔
        if (lineContent[1] != "") {
            host = lineContent[HOSTINDEX];//下标为3的是主机名
        }
        else {
            host = lineContent[HOSTINDEX+1];//下标为4的是主机名
        }
        map.insert("主机名", host);
        lineContent = it->split(host);//以主机名分隔
        leftString = lineContent[0];//日期和时间
        rightString = lineContent[1];
        action = rightString.mid(0, rightString.indexOf(": "));
        map.insert("动作", action);
        description = rightString.mid(rightString.indexOf(": ")+1);
        map.insert("描述", description.simplified());
        formatString(leftString); //去除多余的空格
        lineContent = leftString.split(" ");
        date = month[lineContent[0]] + "-" + lineContent[1];
        map.insert("日期", date);
        time = lineContent[2];
        map.insert("时间", time);
        logList << map;
    }
//    qDebug() << logList;
}

void ParserLog::parserError(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QStringList lineContent;
    QString regExpString = "";
    QRegExp rx;
    QString host = "";
    QString description = "";
    QString leftString = "";
    QString rightString = "";
    QString action = "";
    QString date = "";
    QString time = "";
    QString monthMatch = "^(Jan|Fre|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
    QMap<QString, QString> map;

    getcontent.getErrorContent(allContent);

    //正则匹配表达式
    regExpString = monthMatch + "[ ]*\\d+[ ]*\\d+:\\d+:\\d+[ ]*[^ ][ ]*[^:]+:";
    rx.setPattern(regExpString);
    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        //如果不匹配就跳过
        if (-1 == rx.indexIn(*it)) {
            continue;
        }
        lineContent = it->split(" "); //将字符串以空格为分隔符分隔
        if (lineContent[1] != "") {
            host = lineContent[HOSTINDEX];//下标为3的是主机名
        }
        else {
            host = lineContent[HOSTINDEX+1];//下标为4的是主机名
        }
        map.insert("主机名", host);
        lineContent = it->split(host);//以主机名分隔
        leftString = lineContent[0];//日期和时间
        rightString = lineContent[1];
        action = rightString.mid(0, rightString.indexOf(": "));
        map.insert("动作", action);
        description = rightString.mid(rightString.indexOf(": ")+1);
        map.insert("描述", description.simplified());
        formatString(leftString); //去除多余的空格
        lineContent = leftString.split(" ");
        date = month[lineContent[0]] + "-" + lineContent[1];
        map.insert("日期", date);
        time = lineContent[2];
        map.insert("时间", time);
        logList << map;
    }
    //    qDebug() << logList;
}

void ParserLog::parserCritical(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QStringList lineContent;
    QString regExpString = "";
    QRegExp rx;
    QString host = "";
    QString description = "";
    QString leftString = "";
    QString rightString = "";
    QString action = "";
    QString date = "";
    QString time = "";
    QString monthMatch = "^(Jan|Fre|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
    QMap<QString, QString> map;

    getcontent.getCriticalContent(allContent);

    //正则匹配表达式
    regExpString = monthMatch + "[ ]*\\d+[ ]*\\d+:\\d+:\\d+[ ]*[^ ][ ]*[^:]+:";
    rx.setPattern(regExpString);
    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        //如果不匹配就跳过
        if (-1 == rx.indexIn(*it)) {
            continue;
        }
        lineContent = it->split(" "); //将字符串以空格为分隔符分隔
        if (lineContent[1] != "") {
            host = lineContent[HOSTINDEX];//下标为3的是主机名
        }
        else {
            host = lineContent[HOSTINDEX+1];//下标为4的是主机名
        }
        map.insert("主机名", host);
        lineContent = it->split(host);//以主机名分隔
        leftString = lineContent[0];//日期和时间
        rightString = lineContent[1];
        action = rightString.mid(0, rightString.indexOf(": "));
        map.insert("动作", action);
        description = rightString.mid(rightString.indexOf(": ")+1);
        map.insert("描述", description.simplified());
        formatString(leftString); //去除多余的空格
        lineContent = leftString.split(" ");
        date = month[lineContent[0]] + "-" + lineContent[1];
        map.insert("日期", date);
        time = lineContent[2];
        map.insert("时间", time);
        logList << map;
    }
    //    qDebug() << logList;
}

void ParserLog::parserAlert(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QStringList lineContent;
    QString regExpString = "";
    QRegExp rx;
    QString host = "";
    QString description = "";
    QString leftString = "";
    QString rightString = "";
    QString action = "";
    QString date = "";
    QString time = "";
    QString monthMatch = "^(Jan|Fre|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
    QMap<QString, QString> map;

    getcontent.getAlertContent(allContent);

    //正则匹配表达式
    regExpString = monthMatch + "[ ]*\\d+[ ]*\\d+:\\d+:\\d+[ ]*[^ ][ ]*[^:]+:";
    rx.setPattern(regExpString);
    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        //如果不匹配就跳过
        if (-1 == rx.indexIn(*it)) {
            continue;
        }
        lineContent = it->split(" "); //将字符串以空格为分隔符分隔
        if (lineContent[1] != "") {
            host = lineContent[HOSTINDEX];//下标为3的是主机名
        }
        else {
            host = lineContent[HOSTINDEX+1];//下标为4的是主机名
        }
        map.insert("主机名", host);
        lineContent = it->split(host);//以主机名分隔
        leftString = lineContent[0];//日期和时间
        rightString = lineContent[1];
        action = rightString.mid(0, rightString.indexOf(": "));
        map.insert("动作", action);
        description = rightString.mid(rightString.indexOf(": ")+1);
        map.insert("描述", description.simplified());
        formatString(leftString); //去除多余的空格
        lineContent = leftString.split(" ");
        date = month[lineContent[0]] + "-" + lineContent[1];
        map.insert("日期", date);
        time = lineContent[2];
        map.insert("时间", time);
        logList << map;
    }
    //    qDebug() << logList;
}

void ParserLog::parserEmerg(QList<QMap<QString, QString> > &logList)
{
    GetContent getcontent;
    QStringList allContent;
    QStringList lineContent;
    QString regExpString = "";
    QRegExp rx;
    QString host = "";
    QString description = "";
    QString leftString = "";
    QString rightString = "";
    QString action = "";
    QString date = "";
    QString time = "";
    QString monthMatch = "^(Jan|Fre|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
    QMap<QString, QString> map;

    getcontent.getEmergContent(allContent);

    //正则匹配表达式
    regExpString = monthMatch + "[ ]*\\d+[ ]*\\d+:\\d+:\\d+[ ]*[^ ][ ]*[^:]+:";
    rx.setPattern(regExpString);
    for (QList<QString>::Iterator it=allContent.begin(); it!=allContent.end(); it++) {
        //如果不匹配就跳过
        if (-1 == rx.indexIn(*it)) {
            continue;
        }
        lineContent = it->split(" "); //将字符串以空格为分隔符分隔
        if (lineContent[1] != "") {
            host = lineContent[HOSTINDEX];//下标为3的是主机名
        }
        else {
            host = lineContent[HOSTINDEX+1];//下标为4的是主机名
        }
        map.insert("主机名", host);
        lineContent = it->split(host);//以主机名分隔
        leftString = lineContent[0];//日期和时间
        rightString = lineContent[1];
        action = rightString.mid(0, rightString.indexOf(": "));
        map.insert("动作", action);
        description = rightString.mid(rightString.indexOf(": ")+1);
        map.insert("描述", description.simplified());
        formatString(leftString); //去除多余的空格
        lineContent = leftString.split(" ");
        date = month[lineContent[0]] + "-" + lineContent[1];
        map.insert("日期", date);
        time = lineContent[2];
        map.insert("时间", time);
        logList << map;
    }
//    qDebug() << logList;
}
